var dataTable = null;
function Form_method(str,search_flag) {

    if(str==per){
        if(search_flag==0){
            dataTable = jQuery("#div1").raytable({
                datasource: { data: [], keyfield: 'userId' },
                columns: [
                    //{ title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }], renderIf: isManager },
                    { field: "userId", title: "用户ID", sort:true },
                    { field: "name", title: "用户姓名", sort: true },
                    { field: "birthday", title: "出生日期" ,sort: true,format: parseDate},
                    { field: "sex", title: "性别", sort: true },
                    { field: "phoneNumber", title: "电话号码"  },
                    { field: "emailAddress", title: "邮箱地址", sort: true },
                    { field: "id", title: "身份证号", sort: true },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true
            });
        }
        else{
            dataTable = jQuery("#div1_select").raytable({
                datasource: { data: [], keyfield: 'userId' },
                columns: [
                    //{ title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }], renderIf: isManager },
                    { field: "userId", title: "用户ID", sort:true },
                    { field: "name", title: "用户姓名", sort: true },
                    { field: "birthday", title: "出生日期",sort: true,format: parseDate },
                    { field: "sex", title: "性别", sort: true },
                    { field: "phoneNumber", title: "电话号码"  },
                    { field: "emailAddress", title: "邮箱地址", sort: true },
                    { field: "id", title: "身份证号", sort: true },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true
            });
        }

    }
    else if(str==per2){
        if(search_flag==0){
            dataTable = jQuery("#div2").raytable({
                datasource: { data: [], keyfield: 'shopId' },
                columns: [
                    { title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }] },
                    { field: "shopId", title: "商店ID", sort:true },
                    { field: "shopName", title: "商店名称", sort: true },
                    { field: "createTime", title: "建立时间",sort: true,format: parseDate },
                    { field: "ownerId", title: "店主ID", sort: true },
                    { field: "totalSell", title: "销售总额"  },
                    { field: "count", title: "商品数量", sort: true, },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true,
            });
        }
        else{
            dataTable = jQuery("#div2_select").raytable({
                datasource: { data: [], keyfield: 'shopId' },
                columns: [
                    { title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }] },
                    { field: "shopId", title: "商店ID", sort:true },
                    { field: "shopName", title: "商店名称", sort: true },
                    { field: "createTime", title: "建立时间" ,sort: true,format: parseDate},
                    { field: "ownerId", title: "店主ID", sort: true },
                    { field: "totalSell", title: "销售总额"  },
                    { field: "count", title: "商品数量", sort: true, },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true,
            });
        }
    }
    else if(str==per3){
        if(search_flag==0){
            dataTable = jQuery("#div3").raytable({
                datasource: { data: [], keyfield: 'userId' },
                columns: [
                  // { title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }], renderIf: isManager },
                    { field: "userId", title: "用户ID", sort:true },
                    { field: "userAccount", title: "用户账号", sort: true },
                    { field: "userPassword", title: "密码" },
                    { field: "userName", title: "用户名", sort: true },
                    { field: "address", title: "用户地址"  },
                    { field: "avatar", title: "头像", sort: true, },
                    { field: "identity", title: "身份", sort: true },
                    { field: "createDate", title: "创建日期", sort: true, format: parseDate },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true,
            });
        }
        else{

            dataTable = jQuery("#div3_select").raytable({
                datasource: { data: [], keyfield: 'userId' },
                columns: [
                 //   { title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }], renderIf: isManager },
                    { field: "userId", title: "用户ID", sort:true },
                    { field: "userAccount", title: "用户账号", sort: true },
                    { field: "userPassword", title: "密码" },
                    { field: "userName", title: "用户名", sort: true },
                    { field: "address", title: "用户地址"  },
                    { field: "avatar", title: "头像", sort: true, },
                    { field: "identity", title: "身份", sort: true },
                    { field: "createDate", title: "创建日期", sort: true, format: parseDate },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true,
            });
        }
    }
    else{
        if(search_flag==0){
            dataTable = jQuery("#div4").raytable({
                datasource: { data: [], keyfield: 'goodsId' },
                columns: [
                   // { title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }], renderIf: isManager },
                    { field: "goodsId", title: "商品ID", sort:true },
                    { field: "bookId", title: "书籍ID", sort: true },
                    { field: "bookName", title: "书籍名称" },
                    { field: "goodsImage", title: "商品图片", sort: true },
                    { field: "goodsName", title: "商品名称"  },
                    { field: "shopId", title: "店家ID", sort: true},
                    { field: "shopName", title: "店家名称", sort: true },
                    { field: "remain", title: "库存", sort: true},
                    { field: "price", title: "价格", sort: true },
                    { field: "sell", title: "累计销量", sort: true },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true,
            });
        }
        else{
            dataTable = jQuery("#div4_select").raytable({
                datasource: { data: [], keyfield: 'goodsId' },
                columns: [
                  //  { title: "Info", icons: [{ glyph: "glyphicon-info-sign", handler: iconAction1, data:"id" }], renderIf: isManager },
                    { field: "goodsId", title: "商品ID", sort:true },
                    { field: "bookId", title: "书籍ID", sort: true },
                    { field: "bookName", title: "书籍名称" },
                    { field: "goodsImage", title: "商品图片", sort: true },
                    { field: "goodsName", title: "商品名称"  },
                    { field: "shopId", title: "店家ID", sort: true},
                    { field: "shopName", title: "店家名称", sort: true },
                    { field: "remain", title: "库存", sort: true},
                    { field: "price", title: "价格", sort: true },
                    { field: "sell", title: "累计销量", sort: true },
                    { title: "Delete", icons: [{ glyph: "glyphicon-trash", handler: iconAction2, data: "id" }] }
                ],
                pagesize: 10,
                maxPageButtons: 5,
                rowNumbers: true,
            });
        }
    }

    jQuery(".glyphicon").css('cursor', 'pointer');

    // load some default
    //doLoad(jQuery("#dataTable"));

};

// load some data
function doLoad(a,search_flag) {
    Form_method(a,search_flag);
}

function Show(){
    document.getElementById("div2").style.display="none";
    document.getElementById("div2_select").style.display="none";
    document.getElementById("div4").style.display="block";
    doLoad(per4,0);
    dataTable.data(per4,'goodsId');
}
// icon clicked event handler
function iconAction1(event)
{
    // jquery to get the record ID back out
    Show();
    //alert('You clicked the icon with data = ' + event.data.id + ' on row ' + event.data.rowIdx );
}

function iconAction2(event)
{
    // jquery to get the record ID back out
    var data = jQuery(event.target).data('ray-data');
    alert('glyph icon data is ' + data);
    //alert('You clicked the icon with data = ' + event.data.id + ' on row ' + event.data.rowIdx );
}


// boolean handler to determine if the cell content is rendered
function isManager(item)
{
    return (item.grade > 4);
}

// custom format handler
function parseDate(item)
{
    // source is ISO 8601
    var d = new Date(item.birthDate);
    return d.toDateString();
}
